#include "imagelabel.h"

ImageLabel::ImageLabel(QStatusBar* statusbar, QImage* img)
{
    this->setMouseTracking(true);
    this->statusbar = statusbar;
    this->img = img;
    this->setBackgroundRole(QPalette::Base);
    this->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    this->setScaledContents(true);
    this->setPixmap(QPixmap::fromImage( *(this->img) ));
}

void ImageLabel::mouseMoveEvent(QMouseEvent *event)
{
    int x = event->x();
    int y = event->y();
    QColor color ( this->img->pixel(x,y) );
    QVariant xVar (x);
    QVariant yVar (y);
    QVariant rVar (color.red());
    QVariant gVar (color.green());
    QVariant bVar (color.blue());
    QString str ("Pixel [");
    str.append(xVar.toString());
    str.append(", ");
    str.append(yVar.toString());
    str.append("]: ( R: ");
    str.append(rVar.toString());
    str.append(", G: ");
    str.append(gVar.toString());
    str.append(", B: ");
    str.append(bVar.toString());
    str.append(")");
    this->statusbar->showMessage(str);
}
